﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace SpaceMan.Menus.Items
{
    class C_Button : I_Item
    {
        string buttonAction;
        string buttonText;
        C_DrawText drawText;
        C_Drawing drawButton;
        Vector2 position;
        MouseState MState, LMState;
        Action<string> callCommand;
        public C_Button(Vector2 position, string buttonText, string buttonAction, Action<string> callCommand)
        {
            this.callCommand = callCommand;
            this.position = position;
            this.buttonAction = buttonAction;
            this.buttonText = buttonText;
            drawText.SetText(buttonText);
            rectangle = new Rectangle((int)position.X, (int)position.Y, 256, 64);
        }

        public override void Update(bool isActive, Vector2 Position)
        {
            MState = Mouse.GetState();

            Rectangle pointerPoint = new Rectangle(MState.X, MState.Y, 1, 1);
            if (pointerPoint.Intersects(rectangle) && MState.LeftButton == ButtonState.Pressed && LMState.LeftButton == ButtonState.Released)
            {
                callCommand(buttonAction);
            }


            LMState = MState;
        }

        override public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, DrawMode drawMode, Microsoft.Xna.Framework.Rectangle drawSpace)
        {
            drawButton.Draw(spriteBatch, drawMode, drawSpace);
            drawText.Draw(spriteBatch, drawMode, drawSpace);
        }

        public void Clicked()
        {

        }
    }
}
